﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Tww.MAF.MAFBrowserModule.View;
using Tww.MAF.MAFBrowserModule.ViewModel;
using Tww.MAF.MAFEngine.Navigation.Browser;
using Tww.MAF.MAFEngine.Navigator;

namespace Tww.MAF.MAFBrowserModule
{
    public class MAFBrowserModuleLoader : IModule
    {
        #region Ctors

        public MAFBrowserModuleLoader(IRegionManager regionManager, IUnityContainer unityContainer)
        {
            this.RegionManager = regionManager;
            this.UnityContainer = unityContainer;
        }

        #endregion

        #region Private Properties

        protected IRegionManager RegionManager { get; set; }
        protected IUnityContainer UnityContainer { get; set; }

        #endregion

        public void Initialize()
        {
            this.RegisterTypes();

            this.ShowMenu();
        }

        private void RegisterTypes()
        {
            // Singletons
            this.UnityContainer.RegisterType<IBrowserViewModel, BrowserViewModel>(new ContainerControlledLifetimeManager());
            this.UnityContainer.RegisterType<IBrowserView, BrowserView>(new ContainerControlledLifetimeManager());
        }

        private void ShowMenu()
        {
            var regionManager = this.UnityContainer.Resolve<IRegionManager>();
            regionManager.RegisterViewWithRegion("Browser", typeof (IBrowserView));
        }
    }
}
